package com.ruoyi.djData.controller;

import java.util.List;
import java.util.concurrent.ExecutionException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.djData.domain.plat.DataDj;
import com.ruoyi.djData.service.IDataDjService;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电机数据处理Controller
 * 
 * @author ruoyi
 * @date 2024-01-17
 */
@RestController
@RequestMapping("/data/dj")
@Api(value="电机测试",tags = "电机测试接口")
public class DataDjController extends BaseController
{
    @Autowired
    private IDataDjService dataDjService;

    /**
     * 查询电机数据处理列表
     */
    @PreAuthorize("@ss.hasPermi('djData:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(DataDj dataDj)
    {
        startPage();
        List<DataDj> list = dataDjService.selectDataDjList(dataDj);
        return getDataTable(list);
    }

    /**
     * 获取电机测试结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('djData:task:query')")
    @GetMapping(value = "/getInfoByDataDjTaskId/{dataTaskId}")
    @ApiImplicitParam(paramType="query", name = "dataTaskId", value = "任务id", required = true, dataType = "Long")
    @ApiOperation(value="获取电机测试结果详细信息")
    public AjaxResult getInfoByDataDjTaskId(@PathVariable("dataTaskId") Long dataTaskId) throws ExecutionException, InterruptedException {
        return success(dataDjService.selectDjTaskByDataTaskId(dataTaskId));
    }


    /**
     * 导出电机数据处理列表
     */
    @PreAuthorize("@ss.hasPermi('djData:task:export')")
    @Log(title = "电机数据处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataDj dataDj)
    {
        List<DataDj> list = dataDjService.selectDataDjList(dataDj);
        ExcelUtil<DataDj> util = new ExcelUtil<DataDj>(DataDj.class);
        util.exportExcel(response, list, "电机数据处理数据");
    }

    /**
     * 获取电机数据处理详细信息
     */
    @PreAuthorize("@ss.hasPermi('djData:task:query')")
    @GetMapping(value = "/{djId}")
    public AjaxResult getInfo(@PathVariable("djId") Long djId)
    {
        return success(dataDjService.selectDataDjByDjId(djId));
    }

    /**
     * 新增电机数据处理
     */
    @PreAuthorize("@ss.hasPermi('djData:task:add')")
    @Log(title = "电机数据处理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataDj dataDj)
    {
        return toAjax(dataDjService.insertDataDj(dataDj));
    }

    /**
     * 修改电机数据处理
     */
    @PreAuthorize("@ss.hasPermi('djData:task:edit')")
    @Log(title = "电机数据处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataDj dataDj)
    {
        return toAjax(dataDjService.updateDataDj(dataDj));
    }

    /**
     * 变更电机参数数据
     */
    @PostMapping("/modify")
    @ApiOperation(value="变更电机参数数据")
    public AjaxResult modify(@ApiParam(name="电机参数调整",value="传入json格式",required=true)@RequestBody DataDj dataDj) {
        return AjaxResult.success(dataDjService.modifyDjParam(dataDj));
    }

    /**
     * 根据任务id删除电机测试结果
     */
    @PreAuthorize("@ss.hasPermi('djData:task:remove')")
    @Log(title = "根据任务id删除电机测试结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{djId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "djId", value = "电机机id", required = true, dataType = "Long")
    })
    @ApiOperation(value="根据任务id删除电机测试结果")
    public AjaxResult remove(@PathVariable("djId")Long djId)
    {
        return toAjax(dataDjService.updateDataKDjByDId(djId));
    }

    /**
     * 根据任务id删除整条电机测试结果
     */
    @PreAuthorize("@ss.hasPermi('djData:task:remove')")
    @Log(title = "根据任务id删除整条电机测试结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/updateDataDjByDataTaskId/{dataTaskId}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "dataTaskId", value = "任务id", required = true, dataType = "Long"),
    })
    @ApiOperation(value="根据任务id删除整条电机测试结果")
    public AjaxResult updateDataDjByDataTaskId(@PathVariable("dataTaskId")Long dataTaskId)
    {
        return toAjax(dataDjService.updateDataDjByDataTaskId(dataTaskId));
    }

    /**
     * 删除电机数据处理
     */
    @PreAuthorize("@ss.hasPermi('djData:task:remove')")
    @Log(title = "电机数据处理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{djIds}")
    public AjaxResult remove(@PathVariable Long[] djIds)
    {
        return toAjax(dataDjService.deleteDataDjByDjIds(djIds));
    }

    /**
     * 保存的电机数据导入报告
     */
    @PreAuthorize("@ss.hasPermi('djData:import:query')")
    @PostMapping("/dataDjImportReport")
    @ApiOperation(value="保存的电机数据导入报告")
    public AjaxResult dataDjImportReport(@ApiParam(name="测试项目结果数据",value="传入json格式",required=true)@RequestBody DataDj dataDj){
        return AjaxResult.success(dataDjService.dataDjImportReport(dataDj));
    }
}
